export default {
    namespaced: true,
    state: {
        token: ''
    },
    getters: {},
    mutations: {
        setToken(state, value) {
            state.token = value
            // console.log('token', state.token);
        }
    },
    actions: {
        async getToken({ commit }) {
            // 获取用户个人信息
            const [err1, res1] = await uni.getUserProfile({
                desc: "为用户提供更好的服务",
            });
            //   console.log(res1);
            const { encryptedData, rawData, iv, signature } = res1;
            //  获取临时凭证换取token
            const [err2, res2] = await uni.login();
            //   console.log(res2);
            const { code } = res2;
            //1 获取用户token
            const res3 = await uni.$u.post("/users/wxlogin", {
                encryptedData,
                rawData,
                iv,
                signature,
                code,
            });
            console.log(res3);
            commit('setToken', res3.token)
        }
    }
}